package com.gtapps.user.entity;

import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Cache;

import javax.persistence.*;

@Entity
@Table(name = "user", schema = "test_db", catalog = "")
@DynamicUpdate(true)
//设置开启了二级缓存
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)

public class BaseUserUserEntity {
    private String username;
    private String password;
    //白噢
    /********************************oracle写法***************************
     * SEQUENCE
     *   @GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "normalGenerator")
     *   //这里oracle数据库使用自定义的 主键生成器
     *   @GenericGenerator(name = "normalGenerator", strategy = "uuid")
     *******************************************************************/
    private int id;


    @Basic
    @Column(name = "username")
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Basic
    //这里采用mysql自增主键
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "password")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Id
    @Column(name = "id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        BaseUserUserEntity that = (BaseUserUserEntity) o;

        if (id != that.id) {
            return false;
        }
        if (username != null ? !username.equals(that.username) : that.username != null) {
            return false;
        }
        return password != null ? password.equals(that.password) : that.password == null;
    }

    @Override
    public int hashCode() {
        int result = username != null ? username.hashCode() : 0;
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + id;
        return result;
    }

    @Override
    public String toString() {
        return "BaseUserUserEntity{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", id=" + id +
                '}';

    }


}

